package com.rs.game.player.dialogues.impl;

import com.rs.Settings;
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.game.item.Item;
import com.rs.game.player.content.construction.HouseConstants;
import com.rs.game.player.content.construction.HouseConstants.POHLocation;
import com.rs.game.player.content.construction.HouseConstants.POHLooks;
import com.rs.game.player.dialogues.Dialogue;
import com.rs.utils.ShopsHandler;
import com.rs.utils.Utils;

public class EstateAgent extends Dialogue {

	private int npcId = 4247;

	@Override
	public void start() {
		if (!player.hasHouse) {
			sendEntityDialogue(SEND_2_TEXT_CHAT,new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,  "Hello, I am the estate agent"
					+ "of "+Settings.SERVER_NAME+". I sell properties to build a house. May I intrest you in a property?"}, IS_NPC, npcId, 9827);
			stage = -1;
		} else {
			sendEntityDialogue(SEND_2_TEXT_CHAT,new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,  "How can I help you, "+player.getDisplayName()+ "?"}, IS_NPC, npcId, 9827);
			stage = 8;
		}
	}

	@Override
	public void run(int interfaceId, int componentId) {
		if (stage == -1) {
			sendOptionsDialogue("Would you like to buy a property?", "Yes please", "No thank you.");
			stage = 1;
		} else if (stage == 1) {
			if (componentId == OPTION_1) {
				sendNPCDialogue(npcId, 9827, "You won't regret your buy, it's a lovely property!");
				stage = 2;
			}
			else if (componentId == OPTION_2) {
				end();
			}
		} else if (stage == 2) {
			sendPlayerDialogue(9827, "It sounds amazing! How much exactly does it cost?");
			stage = 3;
		} else if (stage == 3) {
			sendNPCDialogue(npcId, 9827, "The property only costs 1 Million gold coins. It's a bargin as it is reduced from 2 Million gold coins.");
			stage = 4;
		} else if (stage == 4) { 
			sendNPCDialogue(npcId, 9827, "So would you like to buy it now or later?");
			stage = 5;
		} else if (stage == 5) {
			sendOptionsDialogue("Would you like to buy a property for 1 Million gold coins?", "I'd like to buy it now please.", "I'll think about it and come back later.");
			stage = 6;
		} else if (stage == 6) {
			if (componentId == OPTION_1) {
				if (player.getInventory().getCoinsAmount() >= 1000000) {
					sendNPCDialogue(npcId, 9827, "It's been a pleasure doing business, Sir! You can access your house at the house portal which can be found next to me.");
					player.getInventory().removeItemMoneyPouch(new Item(995, 1000000));
					player.hasHouse = true;
					player.spokeToAgent = true;  	
					player.getHouse().location = HouseConstants.POHLocation.RIMMINGTON;
					player.servant = HouseConstants.ServantType.RICK.getId();
					player.getPackets().sendGameMessage("Your servant is: Rick.");
					player.getPackets().sendGameMessage("Your house is located at " + Utils.formatPlayerNameForDisplay(player.getHouse().location.name()) + ".");
					player.setHouseLook(POHLooks.BASIC_WOOD.getLook());
					player.getPackets().sendGameMessage("Your house currently has the look: Basic Wood.");
					player.getPackets().sendGameMessage("These settings can be changed when talking to the Estate Agent again.");
					stage = 7;
				} else {
					sendNPCDialogue(npcId, 9827, "I'm sorry, it looks like you don't have the funds in your inventory, please come back when you do.");
					stage = 7;
				}
			} else if (componentId == OPTION_2) {
				end();
			}
		} else if (stage == 7) { 
			end();
		} else if (stage == 8) {
			sendOptionsDialogue("Estate Agent.", "Can you sell me Construction Supplies?", "Can you change my house style?", "Can you change my house location?", "Never mind.");
			stage = 9;

		} else if (stage == 9) { 
			if (componentId == OPTION_1) {
				sendOptionsDialogue("Estate Agent.", "Materials", "Plants", "Misc", "Never mind.");
				stage = 14;
			} else if (componentId == OPTION_2) {
				sendOptionsDialogue("Choose the house-style you desire", "Basic Wood", "Basic Stone", "Whitewashed Stone", "Fremennik-Style Wood", "More styles...");
				stage = 10;
			} else if (componentId == OPTION_3) {
				sendOptionsDialogue("Choose the location of your house", "Rimmington", "Taverly", 
						"Pollnivneach", "Rellekka", "More locations...");
				stage = 12;
			} else if (componentId == OPTION_4) {
				end(); 
			}
		} else if (stage == 10) {
			if (componentId == OPTION_1) {
				if (player.getSkills().getLevel(22) >= POHLooks.BASIC_WOOD.getLevelrequired() && 
						player.getInventory().getCoinsAmount() >= POHLooks.BASIC_WOOD.getCost()) {
					player.setHouseLook(POHLooks.BASIC_WOOD.getLook());
					player.getInventory().removeItemMoneyPouch(new Item(995, POHLooks.BASIC_WOOD.getCost()));
					player.getPackets().sendGameMessage("You are now using: Basic Wood.");
					end();
				} else { 
					player.getPackets().sendGameMessage("You need "+POHLooks.BASIC_WOOD.getCost()+" coins and level "
							+POHLooks.BASIC_WOOD.getLevelrequired()+" in construction for this style.");
					end();
				} 
			} else if (componentId == OPTION_2) {
				if (player.getSkills().getLevel(22) >= POHLooks.BASIC_STONE.getLevelrequired() && 
						player.getInventory().getCoinsAmount() >= POHLooks.BASIC_STONE.getCost()) {
					player.setHouseLook(POHLooks.BASIC_STONE.getLook());
					player.getInventory().removeItemMoneyPouch(new Item(995, POHLooks.BASIC_STONE.getCost()));
					player.getPackets().sendGameMessage("You are now using: Basic Stone.");
					end();
				} else { 
					player.getPackets().sendGameMessage("You need "+POHLooks.BASIC_STONE.getCost()+" coins and level "
							+POHLooks.BASIC_STONE.getLevelrequired()+" in construction for this style.");
					end();
				}                 		
			} else if (componentId == OPTION_3) {
				if (player.getSkills().getLevel(22) >= POHLooks.WHITEWASHED_STONE.getLevelrequired() && 
						player.getInventory().getCoinsAmount() >= POHLooks.WHITEWASHED_STONE.getCost()) {
					player.setHouseLook(POHLooks.WHITEWASHED_STONE.getLook());
					player.getInventory().removeItemMoneyPouch(new Item(995, POHLooks.WHITEWASHED_STONE.getCost()));
					player.getPackets().sendGameMessage("You are now using: Whitewashed Stone.");
					end();
				} else { 
					player.getPackets().sendGameMessage("You need "+POHLooks.WHITEWASHED_STONE.getCost()+" coins and level "
							+POHLooks.WHITEWASHED_STONE.getLevelrequired()+" in construction for this style.");
					end();
				}                 		
			} else if (componentId == OPTION_4) {
				if (player.getSkills().getLevel(22) >= POHLooks.FREMENNIK_STYLE_WOOD.getLevelrequired() && 
						player.getInventory().getCoinsAmount() >= POHLooks.FREMENNIK_STYLE_WOOD.getCost()) {
					player.setHouseLook(POHLooks.FREMENNIK_STYLE_WOOD.getLook());
					player.getInventory().removeItemMoneyPouch(new Item(995, POHLooks.FREMENNIK_STYLE_WOOD.getCost()));
					player.getPackets().sendGameMessage("You are now using: Fremennik-style Wood.");
					end();
				} else { 
					player.getPackets().sendGameMessage("You need "+POHLooks.FREMENNIK_STYLE_WOOD.getCost()+" coins and level "
							+POHLooks.FREMENNIK_STYLE_WOOD.getLevelrequired()+" in construction for this style.");
					end();
				}                 		
			} else if (componentId == OPTION_5) {
				sendOptionsDialogue("Choose the house-style you desire", "Tropical Wood", "Fancy Stone", "Zenevivia's Dark Stone", "Back");
				stage = 11;      		
			}
		} else if (stage == 11) {
			if (componentId == OPTION_1) {
				if (player.getSkills().getLevel(22) >= POHLooks.TROPICAL_WOOD.getLevelrequired() && 
						player.getInventory().getCoinsAmount() >= POHLooks.TROPICAL_WOOD.getCost()) {
					player.setHouseLook(POHLooks.TROPICAL_WOOD.getLook());
					player.getInventory().removeItemMoneyPouch(new Item(995, POHLooks.TROPICAL_WOOD.getCost()));
					player.getPackets().sendGameMessage("You are now using: Tropical Wood.");
					end();
				} else { 
					player.getPackets().sendGameMessage("You need "+POHLooks.TROPICAL_WOOD.getCost()+" coins and level "
							+POHLooks.TROPICAL_WOOD.getLevelrequired()+" in construction for this style.");
					end();
				} 
			} else if (componentId == OPTION_2) {
				if (player.getSkills().getLevel(22) >= POHLooks.FANCY_STONE.getLevelrequired() && 
						player.getInventory().getCoinsAmount() >= POHLooks.FANCY_STONE.getCost()) {
					player.setHouseLook(POHLooks.FANCY_STONE.getLook());
					player.getInventory().removeItemMoneyPouch(new Item(995, POHLooks.FANCY_STONE.getCost()));
					player.getPackets().sendGameMessage("You are now using: Fancy Stone.");
					end();
				} else { 
					player.getPackets().sendGameMessage("You need "+POHLooks.FANCY_STONE.getCost()+" coins and level "
							+POHLooks.FANCY_STONE.getLevelrequired()+" in construction for this style.");
					end();
				}                 		
			} else if (componentId == OPTION_3) {
				if (player.getSkills().getLevel(22) >= POHLooks.ZENEVIVIAS_DARK_STONE.getLevelrequired() && 
						player.getInventory().getCoinsAmount() >= POHLooks.ZENEVIVIAS_DARK_STONE.getCost()) {
					player.setHouseLook(POHLooks.ZENEVIVIAS_DARK_STONE.getLook());
					player.getInventory().removeItemMoneyPouch(new Item(995, POHLooks.ZENEVIVIAS_DARK_STONE.getCost()));
					player.getPackets().sendGameMessage("You are now using: Zenevivia's Dark Stone.");
					end();
				} else { 
					player.getPackets().sendGameMessage("You need "+POHLooks.ZENEVIVIAS_DARK_STONE.getCost()+" coins and level "
							+POHLooks.ZENEVIVIAS_DARK_STONE.getLevelrequired()+" in construction for this style.");
					end();
				}                 		
			} else if (componentId == OPTION_4) {
				sendOptionsDialogue("Choose the house-style you desire", "Basic Wood", "Basic Stone", "Whitewashed Stone", "Fremennik-Style Wood", "More styles...");
				stage = 10;
			}                 		
		} else if (stage == 12) {
			if (componentId == OPTION_1) {
				player.getHouse().location = POHLocation.RIMMINGTON;
				player.getPackets().sendGameMessage("Your house is now located at: Rimmington.");
				end();
			} else if (componentId == OPTION_2) {
				player.getHouse().location = POHLocation.TAVERLY;
				player.getPackets().sendGameMessage("Your house is now located at: Taverly.");
				end();
			} else if (componentId == OPTION_3) {
				player.getHouse().location = POHLocation.POLLNIVNEACH;
				player.getPackets().sendGameMessage("Your house is now located at: Pollnivneach.");
				end();
			}   else if (componentId == OPTION_4) {
				player.getHouse().location = POHLocation.RELLEKKE;
				player.getPackets().sendGameMessage("Your house is now located at: Rellekka.");
				end();
			}  else if (componentId == OPTION_5) {
				sendOptionsDialogue("Choose the location of your house", "Brimhaven", "Yanille", 
						"Back");
				stage = 13;
			} 
		} else if (stage == 13) {
			if (componentId == OPTION_1) {
				player.getHouse().location = POHLocation.BRIMHAVEN;
				player.getPackets().sendGameMessage("Your house is now located at: Brimhaven.");
				end();
			} else if (componentId == OPTION_2) {
				player.getHouse().location = POHLocation.YANILLE;
				player.getPackets().sendGameMessage("Your house is now located at: Yanille.");
				end();
			} else if (componentId == OPTION_3) {
				sendOptionsDialogue("Choose the location of your house", "Rimmington", "Taverly", 
						"Pollnivneach", "Rellekka", "More locations...");
				stage = 12;
			}
		} else if (stage == 14) {
			if (componentId == OPTION_1) {
				ShopsHandler.openShop(player, 43);
				end();
			} else if (componentId == OPTION_2) {
				ShopsHandler.openShop(player, 44);
				end();
			} else if (componentId == OPTION_3) {
				ShopsHandler.openShop(player, 45);
				end();
			} else if (componentId == OPTION_2) {
				stage = 15;
			}
		} else if (stage == 15) {
			end();
		}
	} 



	@Override
	public void finish() {

	}
}